package com.ymcloud.web.controller.oj;

import com.ymcloud.common.result.Result;
import com.ymcloud.pojo.query.oj.ProblemSubmissionPageQuery;
import com.ymcloud.pojo.vo.common.PageVO;
import com.ymcloud.pojo.vo.oj.ProblemVO;
import com.ymcloud.pojo.vo.oj.SubmissionTableVO;
import com.ymcloud.web.service.oj.ProblemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @PackageName: com.ymcloud.web.controller.user
 * @ClassName: ProblemController
 * @Author: Yemiao
 * @CreateTime: 2025-07-23  12:12
 * @Description: 题目相关接口控制器
 */
@RestController
@Slf4j
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;

    /**
     * 获取题目信息
     * @param problemId 题目唯一标识
     * @return 题目信息
     */
    @GetMapping("/{id}")
    public Result<ProblemVO> getProblemDetail(@PathVariable(value = "id") String problemId) {
        log.info("获取题目信息:{}", problemId);
        ProblemVO problem=problemService.getProblemInfo(problemId);
        return Result.ok(problem);
    }

    /**
     * 查询用户当前题目提交列表
     * @param query 分页查询实体
     * @return 提交列表
     */
    @GetMapping("/submissions")
    public Result<PageVO<SubmissionTableVO>> listProblemSubmissions(@Validated ProblemSubmissionPageQuery query) {
        log.info("查询当用当前题目提交列表：{}",query);
        PageVO<SubmissionTableVO> pageVO = problemService.problemSubmissionList(query);
        return Result.ok(pageVO);
    }

    /**
     * 随机获取一道题目
     * @return 题目唯一标识
     */
    @GetMapping("/random")
    public Result<String> randomProblem() {
        log.info("随机获取一道题目");
        String problemId=problemService.randomProblem();
        return Result.ok(problemId);
    }

}
